﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace RealtyManagementSystem.Web
{
    /// <summary>
    /// RoleLoggedInHandler 的摘要说明
    /// </summary>
    public class RoleLoggedInHandler : IHttpHandler
    {

        public void ProcessRequest ( HttpContext context )
        {
            context.Response.ContentType = "text/plain";

            List<string> roles
                = Roles.GetRolesForUser().ToList();

            if (roles.Contains("Administrators"))
            {
                context.Response.Redirect("~/Admin/Index.aspx");
            }
            else if (roles.Contains("RealtyManagers"))
            {
                context.Response.Redirect("~/RealtyManagers/Index.aspx");
            }
            else if (roles.Contains("Householders"))
            {
                context.Response.Redirect("~/Householders/Index.aspx");
            }
            else
            {
                context.Response.Redirect("~/Default.aspx");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}